<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>


    <script type="text/javascript">
        // 将表情转为字符
        // var str = "表情😀123456"
        // console.log(str)

        function utf16toEntities(str) {
            var patt = /[\ud800-\udbff][\udc00-\udfff]/g; // 检测utf16字符正则
            str = str.replace(patt, function (char) {
                var H, L, code;
                if (char.length === 2) {
                    H = char.charCodeAt(0); // 取出高位
                    L = char.charCodeAt(1); // 取出低位
                    code = (H - 0xD800) * 0x400 + 0x10000 + L - 0xDC00; // 转换算法
                    return "&#" + code + ";";
                } else {
                    return char;
                }
            });
            return str;
        }

        // var str01 = utf16toEntities(str)
        // console.log(str01)


        var s = "&#128512;";//codePoint十进制值

        // 将字符转为表情
        function uncodeUtf16(str) {
            var reg = /\&#.*?;/g;
            var result = str.replace(reg, function (char) {
                var H, L, code;
                if (char.length == 9) {
                    code = parseInt(char.match(/[0-9]+/g));
                    H = Math.floor((code - 0x10000) / 0x400) + 0xD800;
                    L = (code - 0x10000) % 0x400 + 0xDC00;
                    return unescape("%u" + H.toString(16) + "%u" + L.toString(16));
                } else {
                    return char;
                }
            });
            return result;
        };
        // var str02 = uncodeUtf16(s)
        // console.log(str02)
    </script>
    <script src="../javascripts/jquery.js"></script>
    <script type="text/javascript">

        var url = "https://emoji-api.com//categories/smileys-emotion?access_key=220f9a8d08401c7384c8197d531349658b5f11df";
        //步骤一:创建异步对象
        var ajax = new XMLHttpRequest();
        //步骤二:设置请求的url参数,参数一是请求的类型,参数二是请求的url,可以带参数,动态的传递参数starName到服务端
        ajax.open('get',url);
        //步骤三:发送请求
        ajax.send();
        //步骤四:注册事件 onreadystatechange 状态改变就会调用
        ajax.onreadystatechange = function () {

            if (ajax.readyState==4 &&ajax.status==200) {
                //步骤五 如果能够进到这个判断 说明 数据 完美的回来了,并且请求的页面是存在的
                // console.log(ajax.responseText);//输入相应的内容
                var text = JSON.parse(ajax.responseText)
                // document.getElementById('text').textContent =text[0]['codePoint'];

                var number = 0;
                for(let i = 0 ; i<10;i++){
                    var  table = document.getElementById('table');
                    var row = table.insertRow(i);
                    for (let j = 0; j < 10; j++){
                        var cell = row.insertCell(j)
                        var num_ten = Number(parseInt((text[number++]['codePoint']),16).toString(10))
                        var st = '&#'+num_ten+';';
                        var str03 = uncodeUtf16(st);
                        cell.innerHTML = str03
                    }
                }
            }
        }
    </script>
</head>
<body>
<table id="table">

</table>

</body>
</html>